<!DOCTYPE html>
<!--
Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/EmptyPHPWebPage.php to edit this template
-->
<?php
    $frist=!count($_POST);
    session_start();
    if(!$_SESSION['islogin']){
         echo "<script>alert('请先进行登录');window.location.href='login.php'</script>";
    }
    $username = $_SESSION['username'];
    require 'common/common.php';
?>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script>
//            alert(editt.value);
            window.onload=function(){
            //左侧点击切换右侧
                var lis = document.querySelectorAll(".left_box li");
                var items = document.querySelectorAll(".right_box div");
                for(var i =0;i<lis.length;i++){
                    lis[i].index = i;
                    lis[i].addEventListener('click',function(){
                         for(var j =0;j<items.length;j++){
                            lis[j].className="";
                            items[j].style.display="none";
                        }
                        this.className="selected";
                        items[this.index].style.display="block";
                    });
                }
                //左侧tab下拉
                
                for(var j=1;j<2;j++){
                 lis[0].onclick=function(){
                    if(lis[1].style.display==="none"){
                        lis[0].innerHTML="用户管理 &#8594";
                         for(var i =1;i<4;i++){
                            lis[i].style.display="block";
                         }
                    }else{
                         lis[0].innerHTML="用户管理 &#8595";
                         for(var i =1;i<2;i++){
                            lis[i].style.display="none";
                         }
                    }
                };
               }
               for(var j=3;j<6;j++){
                    lis[2].addEventListener('click',function(){
                        if(lis[3].style.display==="none"){
                           lis[2].innerHTML="文章管理 &#8594";
                            for(var i =3;i<6;i++){
                               lis[i].style.display="block";
                            }
                       }else{
                            lis[2].innerHTML="文章管理 &#8595";
                            for(var i =3;i<6;i++){
                               lis[i].style.display="none";
                            }
                       }
                    });     
                };
            
            };
        </script>
        <style>
            *{
                margin:0;
                padding:0;
                list-style:none;
                text-decoration: none;
            }
            .top_box{
               background-color:#2F4F4F;
               width:100%;
               height:100px;
            }
            .top_box h2{
                float:left;
                line-height: 100px;
                margin-left: 10px;
            }
            .top_right{
                float:right;
                margin:26px 10px 0 0;
            }
            .top_right a{
                color:black;
            }
            .left_box{
                float:left;
                width:200px;
                
            }
            .left_box ul{
                height:1000px;
                width:200px;
                background-color:#EAEAEF;
            }
            .left_box li{
                width:200px;
                height:60px;
                text-align: center;
                line-height: 60px;
                font-size:19px;
            }
            .left_box li:hover{
                background-color:#808080;
                color:white;
                cursor:pointer;
            }
            
            .first-contnet{
                display: block;
            }
            .selected{
                background-color:#808080;
                color:white;
            }
            .top_right>h3>span {
                color:#CD7F32;
            }
            .top_right>span{
                display: inline-block;
                margin-bottom: 20px;
            }
            .top_right>a{
                display: inline-block;
                color:#FF7F00;
                margin-top:10px;
            }
            .right_box{
                width: 100%;
                height: 1000px;
                background-color: buttonface;
            }
            .fourth-contnet,
            .second-contnet,
            .third-contnet{
                display: none;
            }
            .first_contnet{
                position:relative;
                float:left;
                margin:150px 0 0 200px;
                width: 1200px;
                height: 500px;
                border:1px solid skyblue;
                background-color: #DCDCDC;

            }
            .first_contnet span{
                display: inline-block;
            }
            .first_contnet .popDiv{
                /*display:none;*/
                position:absolute;
                top:100px;
                left:350px;
                background-color:#fff;
                width: 500px;
                height:300px;
            }
            .first_contnet .popDiv form{
                margin:30px auto;
                width:300px;
            }
            .first_contnet .popDiv form span{
                margin-left:30px;
                font-size: 17px;
            }
            .first_contnet .popDiv form #close{
                margin-left:150px;
            }
            .first_contnet .popDiv input{
                margin-bottom:20px;
            }
            .edit{
                cursor:pointer;
            }
            #close{
                cursor:pointer;
            }
        </style>
    </head>
    <body>

         <div id="cover" style="background: #000; position: absolute; left: 0px; top: 0px; width: 100%; height:100%;   filter: alpha(opacity=30); opacity: 0.3;  z-index: 2 "></div>
        <div class="box">
            <div class="top_box">
                <h2>用户后台管理系统</h2>
                <div class="top_right">
                    <h3> 用户名：<span><?php echo "$username" ?></span></h3>
                        <?php
                        echo "<a  href='quit.php?name=quit'>退出登录</a>"; 
                        ?>
                </div>
            </div>
        
            <div class="left_box ">
                <ul class="list">
                    <li class="text selected">用户管理 &#8594</li>
                    <li class="text">&nbsp;&nbsp;&nbsp;&nbsp;用户创建</li>
                    <li class="text">文章管理 &#8594</li>
                    <li class="text">&nbsp;&nbsp;&nbsp;&nbsp;文章评论管理</li>
                    <li class="text">&nbsp;&nbsp;&nbsp;&nbsp;文章删除</li>
                    <li class="text">&nbsp;&nbsp;&nbsp;&nbsp;文章修改</li>
                </ul>
            </div>
             <div class="right_box">
                 <div class="first_contnet">
                    <table>
                        <thead>
                            <tr>
                                <th><span style="width:160px">ID</span></th>    
                                <th><span style="width:160px">用户名</span></th>  
                                <th><span style="width:240px">用户邮箱</span></th>  
                                <th><span style="width:240px">用户手机号</span></th>
                                <th><span style="width:240px" >操作</th>
                            </tr>
                        </thead>
                        
                        <?php 
                            $totalcount = count(getDataSetBySQL("select * from user order by uid desc"));
                            $sql = "select * from user order by uid asc";
                        ?>
                        <tbody>
                           <?php 
                           $a=array();
                            for($index=0;$index<$totalcount;$index++){
                                ?>
                                 <tr>
                                <th><span style="width:160px; margin:10px 0;"><?php echo getDataSetBySQL($sql)[$index]["uid"]?></span></th>    
                                <th><span style="width:160px"><?php echo getDataSetBySQL($sql)[$index]["username"]?></span></th>  
                                <th><span style="width:240px"><?php echo getDataSetBySQL($sql)[$index]["email"]?></span></th>  
                                <th><span style="width:240px"><?php echo getDataSetBySQL($sql)[$index]["phone"]?></span></th>
                                <th><span style="width:50px" class="edit">编辑</span><span style="width:50px" class="delete">删除</span> </th>
                            </tr>
                            <?php
                            $uid = $_GET["id"];
                            }
                            
                            ?>
                        </tbody>

                    </table>
                     <?php 
                        $sql = "select * from user where uid=$uid";
                     ?>
                     <div class="popDiv" id="popDiv" style="z-index:3">
                         <form action="admin_updata.php?id=<?php echo $uid ?>" method="POST">
                             <span>用户名：<input type="text" placeholder="<?php echo getDataSetBySQL($sql)[0]["username"] ?>" name="username"></input></span> <br/>
                            <span> 邮&nbsp;&nbsp; 箱：<input type="text" name="email"></input></span><br/>
                            <span>手机号：<input type="text" name="phone"></input></span><br/>
                            <span id="close"><input type="submit"></span>
                            <span id="close"><a href="admin.php">取消</a></span>
                         </form>
                         <?php
                           
                            if(!$frist){
                                 $usernamee = $_POST["username"];
                                 $email = $_POST["email"];
                                 $phone = $_POST["phone"];
                                 $sql = "UPDATE user SET username='$usernamee', email = '$email',phone = $phone where uid=$uid";
                                 getResultBySQL($sql);
                                echo "<script>alert('修改成功');window.location.href='admin.php'</script>";
                            }
                            ?>

                     </div>
                </div>
                 <div class="second-contnet ">
                    用户创建    
                 </div>
                 <div class="third-contnet">文章管理</div>
                 <div class="fourth-contnet">文章评论管理</div>
                 <div class="fourth-contnet">文章删除</div>
                 <div class="fourth-contnet">文章修改</div>
             </div>
        </div>
            
        
         <!--遮罩层-->
   
                 
    </body>
</html>
<?php
error_reporting(0);   //防止出现Notice报错，阻断网页运行
session_start();      
if( "$_GET[name]"=="quit"){        //使用GET获取name，判断是否满足条件
    $_SESSION['islogin'] = '';      //重置session
    header('location:admin.php');     //跳转到主页面
}
?>